#include <iostream>
#include <cstdio>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include "Log.hpp"
#include "Common.hpp"
using namespace std;
const string dpath = "/dev/null";
void Daemon(int nochdir,int noclose)
{
	signal(SIGPIPE, SIG_IGN);
    signal(SIGCHLD, SIG_IGN);

	if(fork() > 0)
		exit(0);
	setsid();
	if(nochdir == 0)
		chdir("/");
	if(noclose == 0)
	{
		int fd = open(dpath.c_str(),O_RDWR);
		if(fd == -1)
		{
			LOG(LogLevel::WARNING) << "open " << dpath << " erro";
			return;
		}
		else
		{
			dup2(fd,0);
			dup2(fd,1);
			dup2(fd,2);
			close(fd);
		}
	}


}
